<template>
  <div></div>
</template>

<script>
import { ztDecrypt } from '@/api/modules/career.js';
import { env } from '@/api/root';
export default {
  name: 'careerPathMiddlePage',
  data() {
    return {
      rightsMap: {
        1: '性格测评',
        2: '职业测评',
        3: '完善简历',
        4: '简历诊断',
        5: '竞争力分析',
        6: '咨询辅导',
        7: '职途报告'
      },
      assessmentVersion: uni.getStorageSync('assessmentVersion')
    };
  },
  /*
    这个页面的用处：
    1.每个人都有一个一一对应的二维码
    2.扫码进去后，根据二维码中的信息，传给后端完成绑卡流程
    3.根据绑卡结果，跳转到对应的职途主页
  */
  onLoad(opt) {
    console.log('opt.q', opt.q);

    uni.showLoading({
      title: '加载中...'
    });
    // 适配二维码扫码跳转
    if (opt.q) {
      let paramStr = opt.q.split('%3F')[1];
      this.handleDecrypt(paramStr.substring(8, paramStr.length - 20));
    }
  },
  methods: {
    handleDecrypt(extra) {
      const params = {
        extra
      };
      ztDecrypt(params)
        .then((res) => {
          if (res.code == 200) {
            let jumpUrl = '';
            switch (res.data.rightId) {
              case 1:
                const { personName, userId } = res.data.info;
                let url;
                if (env == 'test') {
                  url = `https://3gtest.crm1001.com/disc/#/disc/result?userId=${userId}&iname=${personName}&from=miniprogram`;
                } else if (env == 'pro' || env == 'pre') {
                  url = `https://3g.crm1001.com/v2/disc/#/disc/result?userId=${userId}&iname=${personName}&from=miniprogram`;
                }
                uni.reLaunch({
                  url:
                    '/pagesSub/public/web/descWebView?link=' +
                    encodeURIComponent(url)
                });
                break;
              case 2:
                jumpUrl = `/pagesSub/careerAssessResultActNew/index?fromWhere=careerPath&personId=${res.data.personId}`;
                // if (!this.assessmentVersion || this.assessmentVersion == '1') {
                //   jumpUrl = `/pagesSub/career/activity/CareerAssessResultAct?fromWhere=careerPath&personId=${res.data.personId}`;
                // } else if (this.assessmentVersion == '2') {
                //   jumpUrl = `/pagesSub/careerAssessResultActNew/index?fromWhere=careerPath&personId=${res.data.personId}`;
                // }
                uni.hideLoading();
                uni.reLaunch({ url: jumpUrl });
                break;
              case 4:
                // 来自职途运营中台的简历诊断二维码，老师看学生的诊断记录
                jumpUrl = `/pagesSub/newResume/resumeAssessment/index?fromWhere=careerPathManage&personId=${res.data.personId}`;
                uni.hideLoading();
                uni.reLaunch({ url: jumpUrl });
                break;
              case 17: // 跳转到AI面评
                jumpUrl = `/pagesSub/companyCenter/interviewAI/majorSearchAI?rightPersonId=${res.data.personId}`;
                uni.hideLoading();
                uni.reLaunch({ url: jumpUrl });
                break;
              default:
                uni.hideLoading();
                uni.showToast({
                  icon: 'none',
                  title: '发生错误，请重新扫码进入',
                  duration: 4000
                });
                break;
            }
          } else {
            uni.hideLoading();
            uni.showToast({
              icon: 'none',
              title: res.status_desc,
              duration: 4000
            });
          }
        })
        .catch((e) => {
          console.log(e);
        });
    }
  }
};
</script>

<style lang="scss" scoped></style>
